<template>
  <view class="index">
    <Banner :imgList="imgList" />
    <Nav />
    <view class="main-index">
      <text class="index-title">精选车源</text>
      <List :data="data" />
    </view>
  </view>
</template>

<script>
import { getBannerList } from '@requests/index'
import { getResourceList } from '@requests/business'
import List from '@components/index/index/list'
import Banner from '@components/index/index/banner'
import Nav from '@components/index/index/nav'

export default {
  name: 'Index',
  components: {
    List,
    Banner,
    Nav
  },
  data() {
    return {
      data: [],
      imgList: []
    }
  },
  created() {
    this.getBannerList()
    this.getResourceCarList({ page: 1 })
  },
  onShareAppMessage() {
    return {
      title: '亿车商'
    }
  },
  methods: {
    //获取banner
    getBannerList() {
      getBannerList()
        .then(res => {
          this.imgList = res.result.list.map(item => item.image_url)
        })
        .catch(e => e)
    },
    //获取首页精选车源
    getResourceCarList(data) {
      getResourceList(data)
        .then(res => {
          this.data = res.result.list
        })
        .catch(e => e)
    }
  }
}
</script>

<style>
.index {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.index-title {
  display: block;
  font-size: 32rpx;
  font-weight: bold;
  padding: 24rpx 0 10rpx 24rpx;
}
</style>
